package com.wawei.seeds.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wawei.seeds.R;
import com.wawei.seeds.model.WalnutMainEvent;

import java.io.Serializable;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by t27891 on 15/6/20.
 */
public class WalnutMainActivityAdapter extends SeedsBaseAdapter<WalnutMainEvent> {

    public WalnutMainActivityAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder holder;
        if(null != view){
            holder = (ViewHolder)view.getTag();
        }
        else{
            view = LayoutInflater.from(context).inflate(R.layout.activity_walnut_hero_list_item, parent, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }

        WalnutMainEvent event = (WalnutMainEvent)getItem(position);
        if(null == event.AD || event.AD.length() == 0){
            holder.eventImage.setVisibility(View.GONE);
        }
        else {
            imageLoader.loadImage(event.AD, holder.eventImage, false, false);
            holder.eventImage.setVisibility(View.VISIBLE);
        }
        holder.titleView.setText(event.title);
        holder.actionView.setText(event.action);
        holder.available.setText(event.available);
        holder.heroView.setText(event.publisher);
        holder.roleView.setText(event.role);

        return view;
    }

    public static class WalnutEventAppointmentMan implements Serializable{
        public String headPortrait;
        public String userName;
        public String brief;
        public String appointmentStatus;
        public String appointmentTime;
        public String userId;
        public String bookingId;
        public String phone;
    }

    static class ViewHolder {
        @InjectView(R.id.walnut_event_image)ImageView eventImage;
        @InjectView(R.id.walnut_event_title)TextView titleView;
        @InjectView(R.id.walnut_event_action)TextView actionView;
        @InjectView(R.id.walnut_event_hero)TextView heroView;
        @InjectView(R.id.walnut_event_hero_role)TextView roleView;
        @InjectView(R.id.walnut_available_amount)TextView available;

        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
